<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;


class Con3 extends AdminController
{
    public function index()
    {
        $list=Db::table('cc_admin_node')->field(['n_id', 'n_name','n_controller','n_model'])->order('n_id', 'ASC')->select();
//        dump($list);die;
        return view('admin@con3/tables',['list' => $list]);
    }

    public function add()
    {
        return view('admin@con3/add');
    }

    public function doAdd(Request $request)
    {
        $p = input('get.'); // 获取GET数据
//        dump($p);die;
        $data = [
            'n_name'     => $p['name'],
            'n_controller'     => $p['controller'],
            'n_model'     => $p['model']

        ];
        $result = Db::table('cc_admin_node')->data($data)->insert();

        if ($result > 0) {
            return $this->success('添加成功!', url('admin/con3/index'));
        } else {
            return $this->error('添加失败!');
        }

    }

    public function edit($id)
    {
        $row = Db::table('cc_admin_node')->find($id);
//        dump($row);die;
        return view('admin@con3/edit',['row'=>$row]);
    }

    public function doEdit(Request $request,$id)
    {
        $info = input('get.');

//        dump($info);die;

        // 手动处理数据
        $data = [
            'n_name'     => $info['name'],
            'n_controller'  => $info['controller'],
            'n_model'   =>  $info['model']
        ];

        $result = Db::table('cc_admin_node')->where('n_id', $id)->update($data);

        if ($result > 0) {
            return $this->success('更新成功!', url('admin/con3/index'));
        } else {
            return $this->error('更新失败!');
        }
    }
}
